package member.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import common.dao.MemberMapper;
import common.pojo.Member;
import common.utils.Constants;
import common.utils.MD5Util;


@Scope("prototype")
@Service
public class MemberServiceImpl {

	@Resource
	private MemberMapper mapper;

	public List<Member> find(int start, int limit) {
		return mapper.queryListByWhere("where deleted="
				+ Constants.NOT_DELETED + " order by create_time desc limit "
				+ start + "," + limit);
	}

	public int queryByCount(Member m) {
		// TODO Auto-generated method stub
		return mapper.queryByCount(m);
	}

	/**
	 * 删除
	 * @param ids
	 * @param adminName
	 */
	public void delete(String ids, String adminName) {
		String[] id = StringUtils.split(ids, ",");
		Member member = new Member();
		for (int i = 0; i < id.length; i++) {
			if (StringUtils.isNotBlank(id[i])) {
				member.setDeleted(Constants.DELETED);
				member.setUpdateName(adminName);
				member.setUpdateTime(new Date());
				member.setId(Integer.valueOf(id[i]));
				mapper.updateBySelective(member);
			}
		}
	}
	
	/**
	 * 增加
	 * @param book
	 * @param dprice 
	 * @param price 
	 */
	public void add(Member member) {
		member.setState(Constants.SHOW);
		member.setDeleted(Constants.NOT_DELETED);
		member.setPassword(MD5Util.md5(member.getPassword()));
		mapper.add(member);
	}
	

	/**
	 * 查询
	 */
	public Member findInfoById(String id) {		
		return mapper.queryById(Integer.parseInt(id));
	}

	/**
	 * 更新
	 * @param b
	 */
	public void update(Member member) {
		member.setPassword(MD5Util.md5(member.getPassword()));
		mapper.updateBySelective(member);
	}


	
}